package com.yowasa.xiuxian.engine.battle.strategy.drop.water;

import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import com.yowasa.xiuxian.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@BS(name="星海游鲸")
@Order(501)
@Component
public class XingHaiYouJing extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;
    @Override
    public ElementEnum getElement() {
        return ElementEnum.WATER;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        int orgAtk = first.getBattleInfo().getSpell();
        int def = second.getBattleInfo().getRes();
        int dmg = battleHelper.calSpell(orgAtk, def);
        int i = RandomUtil.randomInt(3);
        dmg *= (i+4);
        first.getBattleInfo().setCmp(first.getBattleInfo().getCmp() - orgAtk);
        battleHelper.autoAction(this, first, second, content, dmg, "星海游鲸");
        first.getCd().put("星海游鲸", 6);
    }

    @Override
    public void limit(UserBO user) {
        if (user.getElement().get("水") < XiuxianConstants.DEFAULT_ELEMENT_ACTIVITY) {
            throw new HandlerException("学习/使用星海游鲸必须具有水灵根");
        }
    }
    @Override
    public String limitDesc() {
        return "具有水灵根";
    }

    @Override
    public String desc() {
        return "唤出水元素凝聚的巨型鲸鱼，造成高额魔法伤害\ncd5回合 蓝耗1.0倍术法攻击力造成4-7倍术法攻击伤害";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        Integer cd = user.getCd().get("星海游鲸");
        if (cd != null && cd > 0) {
            return false;
        }
        int orgAtk = user.getBattleInfo().getSpell();
        if (user.getBattleInfo().getCmp() < orgAtk) {
            return false;
        }
        return true;
    }
}
